<?php

namespace App\Console\Commands\PolicyUpload;

use App\Console\Commands\OtaPolicyUploadService\PolicyService;
use App\Repositories\Contracts\PolicyUploadInterface;
use Illuminate\Console\Command;

class PolicyDeleteCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'policy:del';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(PolicyUploadInterface $policyUploadInterface)
    {
        //
        while (true) {

            try {

                $where = [
                    'status' => -2
                ];

                $policies = $policyUploadInterface->get($where);
                if ($policies->isNotEmpty()) {

                    foreach ($policies as $key=>$value) {

                        $policyUploadInterface->deletePolicy($value['platform'],$value['policy_code']);
                    }
                }


            } catch (\Exception $exception) {

            }

            sleep(60);
        }
    }
}
